package de.sendorian.app.forumArchive.dundjinni;

import static de.sendorian.app.forumArchive.renamer.Renamers.appendUserShortname;
import static de.sendorian.app.forumArchive.renamer.Renamers.both;
import static de.sendorian.app.forumArchive.renamer.Renamers.capitalizeFirst;
import static de.sendorian.app.forumArchive.renamer.Renamers.removeForbiddenChars;
import static de.sendorian.app.forumArchive.renamer.Renamers.removeHash;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import de.sendorian.app.forumArchive.Config;
import de.sendorian.app.forumArchive.domain.Forum;
import de.sendorian.app.forumArchive.domain.Post;
import de.sendorian.app.forumArchive.domain.Topic;
import de.sendorian.app.forumArchive.finder.Finder;
import de.sendorian.app.forumArchive.finder.ForumFinder;
import de.sendorian.app.forumArchive.renamer.FileRenamer;

@Component
public class DundjinniConfigStrategy extends Config {

	public DundjinniConfigStrategy() {
		config = this;
		baseUrl = "http://www.dundjinni.com/forums/";
		datePattern = Pattern
				.compile("(\\d{2}/\\d{2}/\\d{4}).*at.*(\\d{1,2}:\\d{2}.m)");
		baseUrl = "http://www.dundjinni.com/forums/";
	}


	@Resource(name = "dundjinniForumFinder")
	public void setForumFinder(ForumFinder forumFinder) {
		this.forumFinder = forumFinder;
	}


	@Resource(name = "dundjinniPostFinder")
	public void setPostFinder(Finder<Topic, Post> postFinder) {
		this.postFinder = postFinder;
	}


	@Resource(name = "dundjinniTopicFinder")
	public void setTopicFinder(Finder<Forum, Topic> topicFinder) {
		this.topicFinder = topicFinder;
	}


	@Override
	public FileRenamer getDefaultRenamer() {
		return both(removeHash()).and(capitalizeFirst())
				.and(appendUserShortname()).and(removeForbiddenChars());
	}


	@Override
	public String getZipNameForForum(String forumName) {
		Map<String, String> forumsToZipNames = new HashMap<String, String>();
		forumsToZipNames.put("Contests", "Contests");
		forumsToZipNames.put("Objects and Textures (Fantasy)", "Fantasy");
		forumsToZipNames.put("Objects and Textures (Modern,Sci-Fi)", "SciFi");

		String period = month != null ? month : sStartDate + "_to_" + sEndDate;
		String zipName = forumsToZipNames.get(forumName) != null ? forumsToZipNames.get(forumName) : forumName;
		return zipPrefix + "_" + period + "_" + zipName;
	}
}
